package org.yagnus.stats.samplers.discrete.withreplacement;

import java.util.ArrayList;
import java.util.List;

import org.yagnus.stats.samplers.discrete.ProbabilitySampler;

/**
 * 
 * @author hc.busy
 * 
 * @param <T>
 */
abstract public class WithReplacementSampler<T> extends ProbabilitySampler<T> {

	/**
	 * 
	 * draws a random sample
	 * 
	 * @return the item drawn
	 * 
	 */
	abstract public T draw();

	/**
	 * This mehod is a default implementation of drawing a bunch of things
	 * derived sub-classes should implement more efficient version if they're
	 * available
	 * 
	 * @param n
	 * @return
	 */
	public List<T> draw(int n) {
		List<T> ret = new ArrayList<T>(n);
		for (int i = 0; i < n; ++i) {
			ret.add(draw());
		}
		return ret;
	}

	public WithReplacementSampler(List<T> t) {
		super(t);
	}

	public WithReplacementSampler(List<T> t, List<Double> weights) {
		super(t, weights);
	}
}
